package com.group4.edu.mapper;

import com.group4.edu.entity.Teacher;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.study.util.AUtils;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

/**
 * <p>
 * 讲师 Mapper 接口
 * </p>
 *
 * @author cloud
 * @since 2022-03-10
 */
@Mapper
public interface TeacherMapper extends BaseMapper<Teacher> {


    @SelectProvider(type = SqlProvider.class, method = "select")
    List<Teacher> findByCondition(Teacher teacher);
    public static class SqlProvider {
        public static String select(Teacher teacher) {
            SQL sql = new SQL();
            sql.SELECT("*").FROM("edu_teacher");
            sql.WHERE("is_deleted != 1");
            if (teacher == null) {
                return sql.toString();
            }
            if (AUtils.isNotEmpty(teacher.getName())) {
                sql.WHERE("name=#{name}");
            }
            if (AUtils.isNotEmpty(teacher.getIntro())) {
                sql.WHERE("intro=#{intro}");
            }
            if (teacher.getGmtCreate() != null) {
                sql.WHERE("gmt_create=#{gmtCreate}");
            }
            if (AUtils.isNotEmpty(teacher.getCareer())) {
                sql.WHERE("career=#{career}");
            }
            if (teacher.getIsDeleted() != null) {
                sql.WHERE("is_deleted=#{isDeleted}");
            }
            if (teacher.getGmtModified() != null) {
                sql.WHERE("gmt_modified=#{gmtModified}");
            }
            return sql.toString();
        }
    }
    }


